package com.xiaoxi.exam.dao;

import com.xiaoxi.exam.model.Discount;
import com.xiaoxi.exam.model.DiscountExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface DiscountMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_discount
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    long countByExample(DiscountExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_discount
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int deleteByExample(DiscountExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_discount
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Update({
        "update s_business.t_discount",
        "set deleted_at = now()",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_discount
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Select({
        "insert into s_business.t_discount (user_id, open_id, ",
        "discount_money, created_at, ",
        "updated_at, deleted_at, ",
        "expire_at, desc)",
        "values (#{userId,jdbcType=BIGINT}, #{openId,jdbcType=VARCHAR}, ",
        "#{discountMoney,jdbcType=INTEGER}, #{createdAt,jdbcType=TIMESTAMP}, ",
        "#{updatedAt,jdbcType=TIMESTAMP}, #{deletedAt,jdbcType=TIMESTAMP}, ",
        "#{expireAt,jdbcType=TIMESTAMP}, #{desc,jdbcType=VARCHAR})", 
        " returning id"
    })
    @Options(useGeneratedKeys=true,keyProperty="id")
    long insertReturningId(Discount record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_discount
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Insert({
        "insert into s_business.t_discount (user_id, open_id, ",
        "discount_money, created_at, ",
        "updated_at, deleted_at, ",
        "expire_at, desc)",
        "values (#{userId,jdbcType=BIGINT}, #{openId,jdbcType=VARCHAR}, ",
        "#{discountMoney,jdbcType=INTEGER}, #{createdAt,jdbcType=TIMESTAMP}, ",
        "#{updatedAt,jdbcType=TIMESTAMP}, #{deletedAt,jdbcType=TIMESTAMP}, ",
        "#{expireAt,jdbcType=TIMESTAMP}, #{desc,jdbcType=VARCHAR})"
    })
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insert(Discount record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_discount
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    long insertSelectiveReturningId(Discount record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_discount
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int insertSelective(Discount record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_discount
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    List<Discount> selectByExample(DiscountExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_discount
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Select({
        "select",
        "id, user_id, open_id, discount_money, created_at, updated_at, deleted_at, expire_at, ",
        "desc",
        "from s_business.t_discount",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("com.xiaoxi.exam.dao.DiscountMapper.BaseResultMap")
    Discount selectByPrimaryKey(Long id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_discount
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int updateByExampleSelective(@Param("record") Discount record, @Param("example") DiscountExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_discount
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int updateByExample(@Param("record") Discount record, @Param("example") DiscountExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_discount
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int updateByPrimaryKeySelective(Discount record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_discount
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Update({
        "update s_business.t_discount",
        "set user_id = #{userId,jdbcType=BIGINT},",
          "open_id = #{openId,jdbcType=VARCHAR},",
          "discount_money = #{discountMoney,jdbcType=INTEGER},",
          "created_at = #{createdAt,jdbcType=TIMESTAMP},",
          "updated_at = #{updatedAt,jdbcType=TIMESTAMP},",
          "deleted_at = #{deletedAt,jdbcType=TIMESTAMP},",
          "expire_at = #{expireAt,jdbcType=TIMESTAMP},",
          "desc = #{desc,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Discount record);
}